/*

*/
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 105;
struct Point
{
    int x, y, z;
};

int L, R, C;
Point q[N * N * N];
char map[N][N][N];
int dist[N][N][N];

int dx[6] = {1, 0, -1, 0, 0, 0};
int dy[6] = {0, 1, 0, -1, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};

int bfs(Point start, Point end)
{
    int hh = 0, tt = 0;
    q[0] = start;
    memset(dist, -1, sizeof dist);
    dist[start.x][start.y][start.z] = 0;

    while (hh <= tt)
    {
        Point temp = q[hh++];
        int x = temp.x, y = temp.y, z = temp.z;
        for (int i = 0; i < 6; i++)
        {
            int a = x + dx[i], b = y + dy[i], c = z + dz[i];
            if (a >= 0 && a < L && b >= 0 && b < R && c >= 0 && c < C && map[a][b][c] == '.' && dist[a][b][c] == -1)
            {
                dist[a][b][c] = dist[x][y][z] + 1;

                if (a == end.x && b == end.y && c == end.z)
                    return dist[a][b][c];
                // cout<<a<<' '<<b<<" "<<c<<"   "<<dist[a][b][c]<<endl;
                q[++tt] = {a, b, c};
            }
        }
    }
    return dist[end.x][end.y][end.z];
}

int main()
{
    while (cin >> L >> R >> C, L || R || C)
    {
        Point start, end;
        for (int i = 0; i < L; i++)
            for (int j = 0; j < R; j++)
            {
                cin >> map[i][j];
                for (int k = 0; k < C; k++)
                {
                    char c = map[i][j][k];
                    if (c == 'S')
                        start = {i, j, k};
                    else if (c == 'E')
                    {
                        end = {i, j, k};
                        map[i][j][k] = '.';
                    }
                }
            }
        // cout<<start.x<<" "<<start.y<<" "<<start.z<<endl;
        // cout<<end.x<<" "<<end.y<<" "<<end.z<<endl;
        int d = bfs(start, end);
        if (d == -1)
            cout << "Trapped!" << endl;
        else
            cout << "Escaped in " << d << " minute(s)." << endl;
    }
    return 0;
}